package dao;

import java.util.List;

import modelo.Cliente;

import org.hibernate.Session;
import org.hibernate.Transaction;


public class ClienteDAO extends AbstractDAO {

	public void incluir(Cliente c) {
		Session sessao = fabrica.openSession();
		Transaction transacao = sessao.beginTransaction();
		sessao.save(c);
		transacao.commit();
		sessao.close();
	}
	public void alterar(Cliente c) throws Exception{
		Session sessao = fabrica.openSession();
		Transaction transacao = sessao.beginTransaction();
		sessao.update(c);
		transacao.commit();
		sessao.close();
	}
	public void excluir(Cliente c) {
		Session sessao = fabrica.openSession();
		Transaction transacao = sessao.beginTransaction();
		sessao.delete(c);
		transacao.commit();
		sessao.close();
	}
	public Cliente consultar(String cod) {
		Cliente c=null;
		Session sessao = fabrica.openSession();
		Transaction transacao = sessao.beginTransaction();
		c = (Cliente) sessao.get(modelo.Cliente.class,cod);
		transacao.commit();
		sessao.close();
		return c;
	}
	public List<Cliente> listar() {
		List<Cliente> lista = null;
		String sql = "from modelo.Cliente";
		Session sessao = fabrica.openSession();
		Transaction transacao = sessao.beginTransaction();
		lista = (List<Cliente>) sessao.createQuery(sql).list();
		transacao.commit();
		sessao.close();
		return lista;
	}
}
